<template>
  <div class="mv">
    <ul v-if="artistMv">
      <li v-for="item in artistMv.mvs" :key="item.id">
        <div class="cover">
          <img :src="item.imgurl + '?param=137y103'" :title="item.name" />
          <router-link :to="'/mv?id=' + item.id" class="msk" :title="item.name"></router-link>
          <a href="javascript:;" class="icon-play" @click="$Message({msg:'功能未开发'})"></a>
        </div>
        <p class="albumName">
          <router-link :to="'/mv?id=' + item.id" :title="item.name">{{ item.name }}</router-link>
        </p>
      </li>
    </ul>
    <!-- 分页 -->
    <PageNav
      :total="total"
      :pageSize="12"
      :currentPage="currentPage"
      @currentChange="handleCurrentChange"
      v-if="artistMv"
    ></PageNav>
  </div>
</template>

<script>
import PageNav from '@/components/PageNav/PageNav.vue'
export default {
  components: { PageNav },
  data() {
    return {
      // top50歌曲
      artistMv: null,
      currentPage: 1,
      total: 0,
      params: { limit: 12, offset: 0 }
    }
  },
  methods: {
    // 获取歌手mv
    async getArtistDetail() {
      this.params = Object.assign(this.params, this.$route.query)
      const { data } = await this.$http.get('/artist/mv', { params: this.params })
      // const { data } = await this.$http.get(`/artist/album?id=${this.$route.query.id}&limit=12`)
      // console.log(data)
      this.artistMv = data
    },
    handleCurrentChange(val) {
      this.currentPage = val
      // 更新offset
      this.params.offset = (val - 1) * this.params.limit
      // 将parmas拼接
      const temparr = []
      for (const key in this.params) {
        temparr.push(key + '=' + this.params[key])
      }
      const query = '?' + temparr.join('&')
      // 路由跳转
      this.$router.push('/artist/mv' + query)
      // 重新获取数据
      this.getArtistDetail()
    }
  },
  created() {
    this.getArtistDetail()
    this.total = this.$parent.artistDetail.artist.mvSize
  }
}
</script>

<style lang="less" scoped>
.mv {
  ul {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    top: 0;
    width: 658px;
    // height: 184px;
    padding-top: 28px;
    li {
      flex: 25%;
      margin-bottom: 20px;
      // 专辑封面
      .cover {
        position: relative;
        margin-bottom: 7px;
        cursor: pointer;
        img {
          display: block;
          width: 137px;
          height: 103px;
        }
        .msk {
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          background: url(~@/assets/images/coverall.png) no-repeat;
          background-position: 0 -1170px;
        }
        .icon-play {
          position: absolute;
          top: 50%;
          left: 50%;
          width: 44px;
          height: 44px;
          margin: -22px 0 0 -38px;
          // transform: translateX(-50%) translateY(-50%);
          background: url(~@/assets/images/iconall.png) no-repeat -30px -135px;
        }
      }
      // 标题和作者名
      p {
        width: 118px;
        height: 18px;
        line-height: 18px;
        text-align: left;
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: #666;
      }
      .albumName a {
        font-size: 14px;

        color: black;
      }
    }
    /* 如果最后一行是3个元素 */
    li:last-child:nth-child(4n - 1) {
      margin-right: calc(25%);
    }
    /* 如果最后一行是2个元素 */
    li:last-child:nth-child(4n - 2) {
      margin-right: calc(50%);
    }
  }
}
</style>
